from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-08 14:03:41.930574
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 08, Jan, 2022
Time: 14:03:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6591
Nobs: 530.000 HQIC: -48.1007
Log likelihood: 6143.60 FPE: 9.70105e-22
AIC: -48.3847 Det(Omega_mle): 8.19894e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.395881 0.073426 5.392 0.000
L1.Burgenland 0.101433 0.043007 2.359 0.018
L1.Kärnten -0.113399 0.022158 -5.118 0.000
L1.Niederösterreich 0.175103 0.089467 1.957 0.050
L1.Oberösterreich 0.104326 0.088946 1.173 0.241
L1.Salzburg 0.271228 0.045362 5.979 0.000
L1.Steiermark 0.028818 0.059804 0.482 0.630
L1.Tirol 0.110330 0.048166 2.291 0.022
L1.Vorarlberg -0.076898 0.042602 -1.805 0.071
L1.Wien 0.008999 0.078904 0.114 0.909
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064147 0.161486 0.397 0.691
L1.Burgenland -0.041061 0.094586 -0.434 0.664
L1.Kärnten 0.040215 0.048732 0.825 0.409
L1.Niederösterreich -0.212238 0.196766 -1.079 0.281
L1.Oberösterreich 0.448426 0.195619 2.292 0.022
L1.Salzburg 0.287528 0.099765 2.882 0.004
L1.Steiermark 0.117211 0.131526 0.891 0.373
L1.Tirol 0.307438 0.105932 2.902 0.004
L1.Vorarlberg 0.020525 0.093695 0.219 0.827
L1.Wien -0.023174 0.173535 -0.134 0.894
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208721 0.037523 5.562 0.000
L1.Burgenland 0.092907 0.021978 4.227 0.000
L1.Kärnten -0.007305 0.011324 -0.645 0.519
L1.Niederösterreich 0.229898 0.045721 5.028 0.000
L1.Oberösterreich 0.158860 0.045454 3.495 0.000
L1.Salzburg 0.041337 0.023182 1.783 0.075
L1.Steiermark 0.026120 0.030562 0.855 0.393
L1.Tirol 0.083309 0.024615 3.385 0.001
L1.Vorarlberg 0.054702 0.021771 2.513 0.012
L1.Wien 0.112769 0.040323 2.797 0.005
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136701 0.037548 3.641 0.000
L1.Burgenland 0.039616 0.021992 1.801 0.072
L1.Kärnten -0.014602 0.011331 -1.289 0.197
L1.Niederösterreich 0.164423 0.045751 3.594 0.000
L1.Oberösterreich 0.333099 0.045484 7.323 0.000
L1.Salzburg 0.106829 0.023197 4.605 0.000
L1.Steiermark 0.108621 0.030582 3.552 0.000
L1.Tirol 0.093410 0.024631 3.792 0.000
L1.Vorarlberg 0.053831 0.021785 2.471 0.013
L1.Wien -0.022668 0.040349 -0.562 0.574
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.099315 0.071469 1.390 0.165
L1.Burgenland -0.041804 0.041861 -0.999 0.318
L1.Kärnten -0.046045 0.021568 -2.135 0.033
L1.Niederösterreich 0.144491 0.087083 1.659 0.097
L1.Oberösterreich 0.171759 0.086575 1.984 0.047
L1.Salzburg 0.281193 0.044153 6.369 0.000
L1.Steiermark 0.063319 0.058210 1.088 0.277
L1.Tirol 0.155091 0.046882 3.308 0.001
L1.Vorarlberg 0.094548 0.041467 2.280 0.023
L1.Wien 0.082153 0.076802 1.070 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.099820 0.055377 1.803 0.071
L1.Burgenland 0.019411 0.032436 0.598 0.550
L1.Kärnten 0.052094 0.016711 3.117 0.002
L1.Niederösterreich 0.182856 0.067476 2.710 0.007
L1.Oberösterreich 0.321701 0.067082 4.796 0.000
L1.Salzburg 0.041347 0.034212 1.209 0.227
L1.Steiermark -0.001715 0.045103 -0.038 0.970
L1.Tirol 0.126632 0.036327 3.486 0.000
L1.Vorarlberg 0.063432 0.032130 1.974 0.048
L1.Wien 0.095426 0.059509 1.604 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160648 0.067291 2.387 0.017
L1.Burgenland 0.010575 0.039414 0.268 0.788
L1.Kärnten -0.065340 0.020307 -3.218 0.001
L1.Niederösterreich -0.109389 0.081993 -1.334 0.182
L1.Oberösterreich 0.213655 0.081515 2.621 0.009
L1.Salzburg 0.050644 0.041572 1.218 0.223
L1.Steiermark 0.254583 0.054807 4.645 0.000
L1.Tirol 0.498826 0.044142 11.300 0.000
L1.Vorarlberg 0.066671 0.039043 1.708 0.088
L1.Wien -0.076999 0.072312 -1.065 0.287
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170470 0.074316 2.294 0.022
L1.Burgenland -0.006116 0.043528 -0.140 0.888
L1.Kärnten 0.063735 0.022427 2.842 0.004
L1.Niederösterreich 0.172421 0.090552 1.904 0.057
L1.Oberösterreich -0.076376 0.090024 -0.848 0.396
L1.Salzburg 0.208458 0.045912 4.540 0.000
L1.Steiermark 0.140739 0.060529 2.325 0.020
L1.Tirol 0.054932 0.048750 1.127 0.260
L1.Vorarlberg 0.145629 0.043119 3.377 0.001
L1.Wien 0.128755 0.079861 1.612 0.107
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.423569 0.043178 9.810 0.000
L1.Burgenland -0.005305 0.025290 -0.210 0.834
L1.Kärnten -0.020816 0.013030 -1.598 0.110
L1.Niederösterreich 0.192384 0.052611 3.657 0.000
L1.Oberösterreich 0.234356 0.052305 4.481 0.000
L1.Salzburg 0.039531 0.026675 1.482 0.138
L1.Steiermark -0.020589 0.035168 -0.585 0.558
L1.Tirol 0.090412 0.028324 3.192 0.001
L1.Vorarlberg 0.047926 0.025052 1.913 0.056
L1.Wien 0.021715 0.046400 0.468 0.640
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.031033 0.090518 0.156420 0.136562 0.076198 0.078560 0.019432 0.201385
Kärnten 0.031033 1.000000 -0.030309 0.131213 0.046449 0.081004 0.447327 -0.073613 0.091590
Niederösterreich 0.090518 -0.030309 1.000000 0.303512 0.123810 0.258486 0.060363 0.148951 0.270794
Oberösterreich 0.156420 0.131213 0.303512 1.000000 0.215111 0.286766 0.166514 0.128762 0.221188
Salzburg 0.136562 0.046449 0.123810 0.215111 1.000000 0.122354 0.079643 0.106304 0.125628
Steiermark 0.076198 0.081004 0.258486 0.286766 0.122354 1.000000 0.131492 0.096552 0.015156
Tirol 0.078560 0.447327 0.060363 0.166514 0.079643 0.131492 1.000000 0.060331 0.146028
Vorarlberg 0.019432 -0.073613 0.148951 0.128762 0.106304 0.096552 0.060331 1.000000 -0.014148
Wien 0.201385 0.091590 0.270794 0.221188 0.125628 0.015156 0.146028 -0.014148 1.000000